package com.es.www.kyl.controller.web;

import com.es.www.kyl.bean.R;
import com.es.www.kyl.bean.req.web.CategoryAddReq;
import com.es.www.kyl.bean.req.web.CategoryReq;
import com.es.www.kyl.bean.req.web.CategoryUpdateReq;
import com.es.www.kyl.bean.res.web.CategoryListVO;
import com.es.www.kyl.bean.res.web.CategoryVO;
import com.es.www.kyl.service.CategoryService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Estranger
 * @date 2025/7/31
 * description
 */
@Api(tags = "类型模块")
@RequiredArgsConstructor
@RestController
@RequestMapping("/web/category")
public class CategoryController {

	private final CategoryService categoryService;

	/**
	 * 类型列表
	 */
	@ApiOperation("类型列表")
	@PostMapping("/pageQueryCategoryList")
	public R<PageInfo<CategoryListVO>> pageQueryCategoryList(@RequestBody CategoryReq categoryReq) {
		return R.successResponse(categoryService.pageQueryCategoryList(categoryReq));
	}

	@ApiOperation("一级类型列表")
	@PostMapping("/getTopCategoryList")
	public R<List<CategoryVO>> getTopCategoryList() {
		return R.successResponse(categoryService.getTopCategoryList());
	}

	@ApiOperation("二级类型列表")
	@PostMapping("/getSubCategoryList")
	public R<List<CategoryVO>> getSubCategoryList(@RequestParam Integer parentId) {
		return R.successResponse(categoryService.getSubCategoryList(parentId));
	}

	@ApiOperation("添加类型")
	@PostMapping("/addCategory")
	public R<Void> addCategory(@RequestBody CategoryAddReq categoryAddReq) {
		categoryService.addCategory(categoryAddReq);
		return R.successCommonResponse();
	}

	@ApiOperation("删除类型")
	@PostMapping("/deleteCategory")
	public R<Void> deleteCategory(@RequestParam Integer categoryId) {
		categoryService.removeById(categoryId);
		return R.successCommonResponse();
	}

	@ApiOperation("修改类型")
	@PostMapping("/updateCategory")
	public R<Void> updateCategory(@RequestBody @Validated CategoryUpdateReq categoryUpdateReq) {
		categoryService.updateCategory(categoryUpdateReq);
		return R.successCommonResponse();
	}


}
